package swingTests;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

/**
 * 
 */

/**
 * @author ganeshT
 *
 */
public class KeyPressedListen extends JFrame implements KeyListener{
public static void main(String[] args) {
    new KeyPressedListen();
}
public KeyPressedListen(){
    JTextArea JTA=new JTextArea();
    this.setSize(400, 300);
    this.setVisible(true);
    JTA.addKeyListener(kl22);
    JTA.addKeyListener(this);

    this.add(JTA);
}
/* (non-Javadoc)
 * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
 */
@Override
public void keyPressed(KeyEvent arg0) {
    System.out.println("PRESSED"+arg0.getKeyChar()+ "   "+ arg0.getKeyCode());
    
}

/* (non-Javadoc)
 * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
 */
@Override
public void keyReleased(KeyEvent arg0) {
//    System.out.println("KEYRELEASE "+arg0.getKeyChar()+ "   "+ arg0.getKeyCode());
    
}

/* (non-Javadoc)
 * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
 */
@Override
public void keyTyped(KeyEvent arg0) {
//    System.out.println("TYPED"+arg0.getKeyChar()+ "   "+ arg0.getKeyCode());
    
}
KeyListener kl22= new KeyListener() {
    
    @Override
    public void keyTyped(KeyEvent arg0) {
//        System.out.println("second keyl");
    }
    
    @Override
    public void keyReleased(KeyEvent arg0) {
//        System.out.println("second keyl");
        
    }
    
    @Override
    public void keyPressed(KeyEvent arg0) {
        System.out.println("second keyl");
        
    }
};
}
